{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 'https://class.imooc.com/?c=ios&mc_marking=286b51b2a8e40915ea9023c821882e74&mc_channel=L5\n",
    "import urllib\n",
    "import urllib3\n",
    "import os\n",
    "from bs4 import BeautifulSoup\n",
    "# load url\n",
    "html = urllib.request.urlopen('https://class.imooc.com/?c=ios&mc_marking=286b51b2a8e40915ea9023c821882e74&mc_channel=L5').read()\n",
    "# parse url data 1 html 2 'html.parser' 3 'utf-8'\n",
    "soup = BeautifulSoup(html,'html.parser',from_encoding='utf-8')\n",
    "# img\n",
    "images = soup.findAll('img')\n",
    "print(images)\n",
    "imageName = 0 \n",
    "for image in images:\n",
    "    link = image.get('src')\n",
    "    print('link=',link)\n",
    "    link = 'http:'+link\n",
    "    fileFormat = link[-3:]\n",
    "    if fileFormat == 'png' or fileFormat == 'jpg':\n",
    "        fileSavePath = '/Users/mac/Desktop/DL/'+str(imageName)+'.jpg'\n",
    "        imageName = imageName +1 \n",
    "        urllib.request.urlretrieve(link,fileSavePath)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
